<script >
import { getDepartment } from '@/api/department';

import { transListToTreeData } from '@/utils';
export default{
    props:{
        value:{
            type:Number,
            default:null
        }
    },
    data(){
        return{
            options:[],
            props:{
                label:'name',
                value:'id',
                
            }

        }
    },
    created(){
        this.getDepartments()

    },
    methods:{
        async getDepartments(){
            this.options = transListToTreeData(await getDepartment(),0)
            
        },
        changValue(list){

            // 取到数组的最后一位
            if(list.length >0){
                this.$emit('input',list[list.length-1])
            } else{
                this.$emit('input',null) // 如果长度为0，则将value置为null

            }
        }
    }
}

</script>

<template>
    <!-- elmentui 的级联选择器 -->
    <el-cascader size="mini" :options="options"
    :props="props" separator="-"
    :value="value" @change="changValue"
    />

   
</template>
